// -----------------------------
// Author: 		Dhaenens Gert 
// Creation: 	2/27/2015 8:12:15 PM				
// -----------------------------

#ifndef _SpriteBatch_h
#define _SpriteBatch_h

#include "Common.h"

namespace Flow
{

	class GraphicsManager;
	class ShaderManager;

	class Sprite;

	struct DrawCall;

	class IGraphicsDevice;
	class IMutex;

	class PosTexShader;
	class PosColTexShader;
	class PosTexNegShader;
	class PosColTexNegShader;

	class SpriteBatch
	{
	public:

		friend class GraphicsManager;
		
		void	SetLayer(UInt32 layer);
		UInt32	GetLayer() const;

		void	IncreaseLayer();
		void	DecreaseLayer();

		IMutex*	GetLayerLock() const;

		void	Draw(Sprite* lpSprite, const Vector2& position, SpriteEffect::Enum effect = SpriteEffect::None);
		void	Draw(Sprite* lpSprite, const Vector2& position, UInt32 layer, SpriteEffect::Enum effect = SpriteEffect::None);

		void	DrawRotatedCenter(Sprite* lpSprite, const Vector2& position, Float rotationCenter, SpriteEffect::Enum effect = SpriteEffect::None);
		void	DrawRotatedCenter(Sprite* lpSprite, const Vector2& position, Float rotationCenter, UInt32 layer, SpriteEffect::Enum effect = SpriteEffect::None);

		void	DrawRotatedPivot(Sprite* lpSprite, const Vector2& position, Float rotation, const Vector2& pivot, SpriteEffect::Enum effect = SpriteEffect::None);
		void	DrawRotatedPivot(Sprite* lpSprite, const Vector2& position, Float rotation, const Vector2& pivot, UInt32 layer, SpriteEffect::Enum effect = SpriteEffect::None);

	private:

		SpriteBatch();
		~SpriteBatch();

		static PosTexShader*		s_lpPosTexShader;
		static PosColTexShader*		s_lpPosColTexShader;
		static PosTexNegShader*		s_lpPosTexNegShader;
		static PosColTexNegShader*	s_lpPosColTexNegShader;

		static void					LoadShaders(ShaderManager* lpShaderManager);
		static void					UnloadShaders();

		Bool				Initialize();

		void				Begin();
		void				End(IGraphicsDevice* lpDevice, IMutex* lpGraphicsDeviceLock);

		UInt32				m_Layer;

		IMutex*				m_QueueLock;
		IMutex*				m_LayerLock;

		SpriteBatch(const SpriteBatch& refSpriteBatch);
		SpriteBatch& operator=(const SpriteBatch& refSpriteBatch);
	};

}

#endif